import os
from datetime import datetime

def ComputeTime (time_hour, time_minute, time_second):
    time_file = os.path.join (os.getcwd (), 'SystemFile', 'saveTime.txt')
    
    if os.path.exists (time_file):
        with open (time_file, 'r') as file:
            last_time = datetime.strptime (file.read ().strip (), '%Y-%m-%d %H:%M:%S')
    else :
        last_time = False
    
    current_time = datetime.now ()
    current_time_str = current_time.strftime('%Y-%m-%d %H:%M:%S')

    with open(time_file, 'w') as file:
        file.write(current_time_str)

    if last_time:
        time_interval = current_time - last_time
        total_seconds = time_interval.total_seconds ()
        hours_interval = int (total_seconds // 3600)
        minutes_interval = int ((total_seconds % 3600) // 60)
        seconds_interval = int (total_seconds - (hours_interval * 3600) - (minutes_interval * 60))
        s = time_second + seconds_interval
        m = time_minute + minutes_interval
        h = 0
        if (s >= 60):
            m += s // 60
            s = m % 60
        if (m >= 60):
            h = m // 60
            m %= 60
        time_hour += h + hours_interval
        time_minute = m
        time_second = s
        
    return time_hour, time_minute, time_second
            
# 调试用
if __name__ == "__main__":
    ComputeTime (1, 2)